package com.zdp.applet.rabbit.producer;

import com.zdp.common.constant.RabbitConstants;
import com.zdp.common.domain.rabbit.FreezeStockMessage;
import com.zdp.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sesshomaru
 * @date 2021/7/11 12:21
 */
@Slf4j
@Service
public class ItemSpecProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息冻结库存
     */
    public void sendFreezeStockMessage(FreezeStockMessage freezeStockMessage) {
        rabbitTemplate.convertAndSend(RabbitConstants.APPLET_EXCHANGE,
                RabbitConstants.APPLET_EXCHANGE_WITH_FREEZE_STOCK_QUEEN_KEY,
                JsonUtils.objectToJson(freezeStockMessage));
        log.info("发送冻结库存消息成功 FreezeStockMessage: {}", JsonUtils.objectToPrettyJson(freezeStockMessage));
    }
}
